/*
 * @Description:处理树的数据
 * @Version: 2.0
 * @Autor: kafei
 * @Date: 2021-11-29 11:00:22
 * @LastEditors: kafei
 * @LastEditTime: 2021-11-29 11:26:41
 */
export const findLastChildren = (data, pId, result = [], key) => {
  if (!data || data.length === 0) {
    return result
  }
  for (let i = 0; i < data.length; i++) {
    const target = data[i]
    if (target[key] === pId) {
      if (target.children && target.children.length > 0) {
        findLastChildren(target.children, target.children[0][key], result, key)
      } else {
        result.push(target)
      }
    }
  }
  return result
}
